<?php

namespace Constructor;

class Builder extends AbstractBuilder
{
    public function __construct( $instances = NULL )
    {
        if( is_null( $instances ) OR ! ( $instances instanceof Instances ) ) 
        {
            throw new BaseValueException( 'instances', $instances, 'Instance of Constructor\Instances' );
        }
        
        parent::__construct( $instances );
    }
    
    public function get( $identifier = NULL )
    {
        if( is_null( $identifier ) OR ! is_string( $identifier ) OR empty( $identifier ) ) 
        {
            throw new BaseValueException( 'identifier', $identifier, 'string' );
        }
        
        if( isset( $this->aliases[ $identifier ] ) ) $identifier = $this->getAlias( $this->aliases[ $identifier ] ); 
        
        return parent::get( $identifier ); 
    }
    
    public function getAlias( $identifier = NULL )
    {
        if( ! is_string( $identifier ) OR is_null( $identifier ) OR empty( $identifier ) ) 
        {
            throw new BaseValueException( 'identifier', $identifier, 'string' );
        }
        
        return parent::getAlias( $identifier );
    }
    
    public function has( $identifier ) 
    { 
        if( ! is_string( $identifier ) OR is_null( $identifier ) OR empty( $identifier ) ) 
        {
            throw new BaseValueException( 'identifier', $identifier, 'string' );
        }
        
        return parent::has( $identifier ); 
    }
    
    public function register( $alias, $identifier = NULL ) 
    {
        if( ! is_string( $alias ) OR is_null( $alias ) OR empty( $alias ) ) 
        {
            throw new BaseValueException( 'alias', $alias, 'string' );
        }
        
        if( ! is_string( $alias ) OR is_null( $alias ) OR empty( $alias ) ) $identifier = $alias;
        
        return parent::register( $alias, $identifier );
    }
}
